package com.ezbuy.common.request;


import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;

public class RequestSubjectImpl implements RequestSubject {

    private List<RequestObserver> resources = new LinkedList<>();

    public static RequestSubjectImpl newInstance() {
        return new RequestSubjectImpl();
    }

    @Override
    public void notifyAllObservers() {
        Iterator<RequestObserver> iterator = resources.iterator();
        while (iterator.hasNext()) {
            RequestObserver resource = iterator.next();
            resource.cancle();
            iterator.remove();
        }
    }

    @Override
    public void attach(RequestObserver resource) {
        resources.add(resource);
    }
}
